using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace BaoCao
{
    public class Transparency
    {
        public class TransparencyForm
        {
            private Timer timer1;
            private bool open;
            private Form frm;

            public bool Open
            {
                get { return this.open; }
                set 
                {
                    this.open = value;
                }
            }
            public int Interval
            {
                get { return this.timer1.Interval; }
                set 
                {
                    this.timer1.Interval = value;
                }
            }
            public double Opacity
            {
                get { return this.frm.Opacity; }
                set { this.frm.Opacity = value; }
            }

            public TransparencyForm(Form frm, bool open, int interval, double intialOpacity)
            {
                try
                {
                    this.frm = frm;
                    this.timer1 = new Timer();
                    this.timer1.Tick += new EventHandler(timer1_Tick);
                    this.Open = open;
                    this.Interval = interval;
                    this.Opacity = intialOpacity;
                }
                catch { }
            }

            private void timer1_Tick(object sender, EventArgs e)
            {
                this.frm.Show();
                if (this.Open)
                    ProcessStart();
                else
                    ProcessClear();
            }
            private void ProcessClear()
            {
                this.Opacity -= 0.1;
                if (this.Opacity <= 0)
                {
                    this.Stop();
                    this.frm.Hide();
                }
            }
            private void ProcessStart()
            {
                this.Opacity += 0.1;
                if (this.Opacity >= 0.9)
                {
                    this.Stop();
                    this.open = false;
                }
            }
            
            public void Start()
            {
                this.timer1.Enabled = true;
            }
            public void Stop()
            {
                this.timer1.Enabled = false;
            }
        }
    }
}
